package genedit.gui.propertyDialogs;

import genedit.gui.GMainFrame;
import genedit.model.graph.classModel.CompositionLink;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class CompositionLinkDialog  extends JDialog {
	
	protected JFrame parent;
	protected GMainFrame mf = GMainFrame.getInstance();
	protected CompositionLink linkComposition;
	protected JButton btnOkDialog;
	protected PanelDetailCompositionLink panelComposition;
	
	public CompositionLinkDialog(JFrame parent, CompositionLink link) {
		super(parent, true);
		
		linkComposition = link;
		this.parent = parent;
		
		setTitle(linkComposition.getName());		;
		setSize(mf.getWidth()/3, 2*mf.getHeight()/5);
		setLocationRelativeTo(parent);
		
		panelComposition = new PanelDetailCompositionLink(linkComposition);
		add(panelComposition, BorderLayout.CENTER);
		
		JPanel panSouth = new JPanel();
		panSouth.setLayout(new BoxLayout(panSouth, BoxLayout.PAGE_AXIS));
		 btnOkDialog = new JButton(GMainFrame.getInstance().getResourceBundle().getString("btnOk"));
		 btnOkDialog.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
						linkComposition.setName(panelComposition.getTxtName().getText());
						linkComposition.setMultiplicityStart((String)panelComposition.getCmbMultiplicity1().getSelectedItem());
						linkComposition.setMultiplicityEnd((String)panelComposition.getCmbMultiplicity2().getSelectedItem());
						linkComposition.setRoleNameStart((String)panelComposition.getTxtRoleName1().getText());
						linkComposition.setRoleNameEnd((String)panelComposition.getTxtRoleName2().getText());
						setVisible(false);
			}
		});
		 btnOkDialog.setAlignmentX( 
				Component.CENTER_ALIGNMENT); 
		panSouth.add(Box.createVerticalGlue()); 
		panSouth.add(btnOkDialog); 
		panSouth.add(Box.createVerticalGlue());;
		add(panSouth, BorderLayout.SOUTH);
		
		pack();
	}
	
	
}
